<?php
namespace app\api\controller;


use think\Db;
/**
 * @title 新闻焦点
 * @description 接口说明
 * @group api
 *
 */
class News extends Base
{
    protected $_order = 'top desc, sort asc,id desc';

    /**
     * @title 获取
     * @description 接口说明
     * @author hardy
     * @url /api/News
     * @method GET
     *
     * @param name:id type:int require:0 default:1 other: desc:唯一ID，获取某条记录详情，则为必填，id和page选填其一
     * @param name:page type:int require:0 default:1 other: desc:页码数 获取第二页以上的数据必填，默认值为1，id和page选填其一
     * @param name:size type:int require:0 default:20 other: desc:每一页的数量，默认20
     *
     * @param name:top type:int require: default:1 other: desc:置顶，条件查询可选条件，等于1则表示加上这个条件
     * @param name:home type:int require: default:1 other: desc:首页展示，条件查询可选条件，等于1则表示加上这个条件
     * @param name:newest type:int require: default:1 other: desc:最新，条件查询可选条件，等于1则表示加上这个条件
     *
     * @return title:文章标题
     *
     * @return tags:标签
     * @return changge_time:更新时间
     * @return content:内容
     * @return auth:作者
     * @return page_view:浏览量
     * @return init_view:初始浏览量
     * @return list_style:列表样式， 0无图，1单图，3三图
     * @return photo_links:图片地址
     * @return top:置顶，0否，1是
     * @return home:首页展示，0否，1是
     * @return newest:最新，，0否，1是
     * @return cover_link:封面地址
     * @return attachment:附件地址
     * @return sort:排序
     * @return publish:0待发布，1已发布，2已下架
     *
     * @return list:消息列表,有page参数则返回值list，list是一个数组，
     * @return size:每页最大数，默认20，可由前端传递参数决定 page参数返回值，
     * @return page:当前页，page参数返回值，
     * @return count:总记录数， page参数返回值，
     */
    public function gets()
    {
        parent::gets();

    }

    /**
     * @title 热度排行
     * @description 接口说明
     * @author wang
     * @url /api/News
     *
     * @header name:Accept require:1 default:application/json,version=2 desc:请求接口版本信息
     * @method GET
     *
     *
     * @return title:文章标题
     *@return tab:文章从哪个表查询出来的
     * @return page_view:浏览量
     * @return id:文章id
     */
    public function gets_v2(){

        $result = Db::field('page_view,id,title,tab')
            ->table('tp_alliance')
            ->union('select page_view,id,title,tab from tp_news WHERE `delete_time`=NULL')
            ->union('select page_view,id,title,tab from tp_policy_consult WHERE `delete_time`=NULL')
            ->union('select page_view,id,title,tab from tp_business WHERE `delete_time`=NULL')
            ->order('page_view desc')
            ->where('delete_time','=',null)
            ->limit(10)
            ->select();

        $this->responseSuccess($result);

    }

    /**
     * @title 最新资讯文章
     * @description 接口说明
     * @author wang
     * @url /api/News
     *@header name:Accept require:1 default:application/json,version=3 desc:请求接口版本信息
     * @method GET
     *
     *
     * @return title:文章标题
     *
     * @return cover_link:封面图片地址
     * @return update_time:更新时间
     * @return id:文章id
     *@return tab:文章从哪个表查询出来的
     */
    public function gets_v3(){

        $result = Db::field('cover_link,page_view,id,title,tab,change_time,delete_time')
            ->table('tp_alliance')
            ->union('select cover_link,page_view,id,title,tab,change_time,delete_time from tp_news WHERE `delete_time`=NULL')
            ->union('select cover_link,page_view,id,title,tab,change_time,delete_time from tp_policy_consult WHERE `delete_time`=NULL ')
            ->order('change_time desc')
            ->where('delete_time','=',null)
            ->limit(10)
            ->select();

        $this->responseSuccess($result);

    }
    /**
     * @title 首页轮播图文章
     * @description 接口说明
     * @author wang
     * @url /api/News
     *@header name:Accept require:1 default:application/json,version=4 desc:请求接口版本信息
     * @method GET
     *
     *
     * @return title:文章标题     *
     * @return cover_link:封面图片地址
     * @return home:是否首页展示
     * @return id:文章id
     *@return tab:文章从哪个表查询出来的
     *

     */
    public function gets_v4(){

        $result = Db::field('cover_link,home,id,title,tab')
            ->table('tp_alliance')
            ->union('select cover_link,home,id,title,tab from tp_news where `home` LIKE 1 AND `delete_time`=NULL')
            ->union('select cover_link,home,id,title,tab from tp_policy_consult where `home` LIKE 1 AND `delete_time`=NULL ')
            ->union('select cover_link,home,id,title,tab from tp_business where `home` LIKE 1 AND `delete_time`=NULL')
            ->where('home','like','1')
            ->where('delete_time','=',null)
            ->limit(10)
            ->select();

        $this->responseSuccess($result);

    }
    protected function _searchPage(&$where)
    {
        $data = input('get.');
        $key = 'title';
        if(!empty($data[$key])){
            $where[] = [$key,'like', "%{$data[$key]}%"];
        }
        $key = 'tags';
        if(!empty($data[$key])){
            $where[] = [$key,'like', "%{$data[$key]}%"];
        }
        $key = 'auth';
        if(!empty($data[$key])){
            $where[] = [$key,'like', "%{$data[$key]}%"];
        }
        // $where[] = ['publish','=', 1];
        $key = 'top';
        if(isset($data[$key])){
            $where[] = [$key,'like', $data[$key]];
        }
        $key = 'home';
        if(!empty($data[$key])){
            $where[] = [$key,'like', "%\"show\": true%"];
        }
        $key = 'newest';
        if(!empty($data[$key])){
            $where[] = [$key,'=', 1];
        }
    }
}